package ajo;

import static org.junit.Assert.assertTrue;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests that BattleBot moves away from walls after it hits them.
 * 
 * @author Joshua Antonio
 */
public class TestBattleBotMovement2 extends RobotTestBed {

  boolean hitWall = false;

  /**
   * Specifies that SpinBot and BattleBot are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {

    return "sample.SpinBot,ajo.BattleBot";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {

    return 10;
  }

  /**
   * Check if in the previous turn BattleBot hit a wall. If it did, check that it did not hit a wall
   * again this turn.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot battleBot = event.getTurnSnapshot().getRobots()[1];
    if (battleBot.getState().isHitWall()) {
      this.hitWall = true;
    }
    else if (this.hitWall) {
      assertTrue(!battleBot.getState().isHitWall());
    }
  }
}